package anything;

/*Regenerating XML  file*/
import java.io.*;
import org.w3c.dom.*;
import org.xml.sax.*;
import javax.xml.parsers.*;
import javax.xml.transform.*; 
import javax.xml.transform.dom.*; 
import javax.xml.transform.stream.*;

public class GetElementsDOM {
  static public void main(String[] arg)throws IOException,SAXException,TransformerException {
    /*BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Enter XML File Name: ");
    String xmlFile = bf.readLine();*/
    File file = new File("res/test/Employee-Detail.xml");
    if(file.exists()){
      //Create a factory  
      try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        //Use document builder factory
        DocumentBuilder builder = factory.newDocumentBuilder();
        //Parse the document
        Document doc = builder.parse(file); 
        TransformerFactory tranFact = TransformerFactory.newInstance(); 
        Transformer transfor = tranFact.newTransformer(); 
        Node node = doc.getDocumentElement();
        Source src = new DOMSource(node); 
        Result dest = new StreamResult(System.out);
        transfor.transform(src, dest);
      }
      catch(ParserConfigurationException e) {
        System.err.println(e);
        System.exit(1);
      }
    }
    else{
      System.out.print("File not found!");
    }
  }
}